package com.lxk.service.impl;

import com.lxk.dao.AsMyMapper;
import com.lxk.dao.CashoutMapper;
import com.lxk.pojo.Cashout;
import com.lxk.pojo.CashoutExample;
import com.lxk.service.CashoutService;
import com.lxk.vo.CashoutModel;
import com.lxk.vo.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author JohnSoybean
 * @create 2020/4/3 19:23
 * @description
 */
@Service
@Transactional
public class CashoutServiceImpl implements CashoutService {

    @Autowired
    private CashoutMapper cm;
    @Autowired
    private AsMyMapper mm;

    public Integer getCashoutPages(Integer num) {
        CashoutExample example = new CashoutExample();
        Integer count = (int)cm.countByExample(example);
        Integer totalPages = count%num==0 ? count/num : count/num+1;
        return totalPages;
    }

    public PageModel<CashoutModel> selCashoutPage(Integer pageIndex, Integer num, Integer totalPages, Integer sort, Integer order) {
        int start = (pageIndex-1)*num;
        List<CashoutModel> list = mm.selCashoutPage(start, num, sort, order);
        PageModel<CashoutModel> model = new PageModel<CashoutModel>();
        model.setList(list);
        model.setNum(num);
        model.setPageIndex(pageIndex);
        model.setTotalPages(totalPages);
        return model;
    }

    public Integer updCashout(Cashout cashout) {
        int upd = cm.updateByPrimaryKeySelective(cashout);
        return upd;
    }

    public Cashout selCashout(Integer cashoutId) {
        Cashout cashout = cm.selectByPrimaryKey(cashoutId);
        return cashout;
    }
}
